﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TenderSampleApp.Models;
using TenderSampleApp.Areas.DAK.Models;
using System.Text.RegularExpressions;
using System.IO;

namespace TenderSampleApp.Areas.DAK.Controllers
{
    public class CreateAuctionController : Controller
    {
        //
        // GET: /DAK/CreateAuction/

        public ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        public ActionResult CreateNewAuction()
        {
            DAKDAL dl = new DAKDAL();
           List<Auction> aucs= dl.GetAuctions();
           ViewData["AucList"] = aucs;
            return View();
        }
        [HttpPost]
        public ActionResult CreateNewAuction(Auction auc, HttpPostedFileBase etpdec)
        {
            if (etpdec != null && etpdec.ContentLength > 0)
            {
                // extract only the fielname
                var fileName = Path.GetFileName(etpdec.FileName);
                // store the file inside ~/App_Data/uploads folder
                var path = Path.Combine(Server.MapPath("~/Content/uploads"), fileName);
                etpdec.SaveAs(path);
                new DAKDAL().LoadEpdtecVatToAuction(path, auc);
            }
            return RedirectToAction("LoadExcelBankFile", "DAKValidRequest", null);
        }

        [HttpGet]
        public ActionResult AddVatToAuction(string num)
        {
            DAL dl = new DAL();

            VATListModel listVat = dl.GetVatsOfAuction(num);

            return View(listVat);
        }

        [HttpPost]
        public ActionResult AddVatToAuction(VATListModel list)
        {
            var t = ViewData.Model;
            List<VATModel> checkedVAT = new List<VATModel>();
            foreach (VATModel vat in list.list)
            {
                if (vat.Checked)
                    checkedVAT.Add(vat);
            }
            return View();
        }

        [HttpGet]
        public ActionResult EditVatModel(int id,string num)
        {
            ViewData["aucnum"] = num;
            VATModel vm = new DAL().GetVATinAuction(id, num);
            return View(vm);
        }

        [HttpPost]
        public ActionResult EditVatModel(VATModel vm, string num)
        {
            ViewData["aucnum"] = num;
            new DAL().UpdateVAT(vm, num);
            return View(vm);
        }
    }
}
